//
//  MemberWelfareSecondGoodsCollectionViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberWelfareSecondGoodsCollectionViewCell.h"

@interface MemberWelfareSecondGoodsCollectionViewCell ()

@property (strong, nonatomic) UIView *bgView;

@property (strong, nonatomic) UIImageView *goodIV;
@property (strong, nonatomic) UILabel *titleL;
@property (strong, nonatomic) UILabel *priceL;

@end

@implementation MemberWelfareSecondGoodsCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self.contentView addSubview:self.bgView];
        [self.contentView addSubview:self.goodIV];
        [self.contentView addSubview:self.titleL];
        [self.contentView addSubview:self.priceL];
        
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        
    }];
    [self.goodIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.height.mas_equalTo(jisuan(180));

    }];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(18));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(18));
        make.top.mas_equalTo(weakSelf.goodIV.mas_bottom).with.offset(jisuan(20));
    }];
    [self.priceL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.titleL.mas_left);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(14));
    }];
    
}

- (void)setGoodListModel:(SupportCategoryGoodListModel *)goodListModel {
    
    NSString *urlString = @"";
    if ([goodListModel.goods_url hasPrefix:@"http://"] || [goodListModel.goods_url hasPrefix:@"https://"]) {
        urlString = goodListModel.goods_url;
    }else {
        urlString = [NSString stringWithFormat:@"http://%@",goodListModel.goods_url];
    }
    [self.goodIV sd_setImageWithURL:[NSURL URLWithString:urlString]];
    self.titleL.text = goodListModel.title;
    self.priceL.text = [NSString stringWithFormat:@"%.2f",[goodListModel.price floatValue] - [goodListModel.dintegral floatValue]];
}

#pragma mark -lazy
- (UIView *)bgView {
    
    if (!_bgView) {
        
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = WhiteColor;
        _bgView.layer.cornerRadius = jisuan(10);
        _bgView.layer.shadowColor = Colorb6b6b6.CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(0, 0);
        _bgView.layer.shadowOpacity = 0.5;
        _bgView.layer.shadowRadius = jisuan(5);
        
    }
    
    return _bgView;
}

- (UIImageView *)goodIV {
    
    if (!_goodIV) {
        
        _goodIV = [[UIImageView alloc] init];
        _goodIV.contentMode = UIViewContentModeScaleAspectFit;
    }
    
    return _goodIV;
}

- (UILabel *)titleL {
    
    if (!_titleL) {
        
        _titleL = [[UILabel alloc] init];
        _titleL.textColor = Color333333;
        _titleL.font = Font(20);
        _titleL.numberOfLines = 2;
        
        NSString *str = @"Air Jordan 1 男子运动 鞋焕新演绎啊啊啊…";

        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = jisuan(3);
        [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, str.length)];
        _titleL.attributedText = attributeStr;
        
        _titleL.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _titleL;
    
}
- (UILabel *)priceL {
    
    if (!_priceL) {
        
        _priceL = [[UILabel alloc] init];
        _priceL.textColor = Color333333;
//        _priceL.textColor = Color333333;
        _priceL.textAlignment = NSTextAlignmentLeft;
        
        NSString *str = @"￥ 949.00";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        [attributeStr addAttribute:NSFontAttributeName value:Font(14) range:NSMakeRange(0, 1)];
        [attributeStr addAttribute:NSFontAttributeName value:Font(28) range:NSMakeRange(1, str.length - 1)];
        _priceL.attributedText = attributeStr;
        
    }
    
    return _priceL;
    
}


@end
